<template>
  <div class="header-box">
    <div class="h-left">
      <img class="logo" src="../../assets/images/logo.png" alt="" />
    </div>
    <div class="h-center">
      <div class="c-bg"></div>
      <div class="c-text">{{ LabName }}</div>
    </div>
    <div class="h-right">
      {{ timeInfo.dateYear }}&nbsp;&nbsp;{{ timeInfo.dateDay }}
      <div class="system" @click="changeCom"><img src="../../assets/images/change.png" alt=""> 切换公司</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, onMounted, onUnmounted, ref, defineEmits } from "vue"
import { formatTime } from "@/utils/index"
import { WEEK } from "@/constant/index"
const LabName = ref('')
const timeInfo = reactive({
  setInterval: 0,
  dateDay: "",
  dateYear: "",
  dateWeek: "",
})
// 生命周期
onMounted(() => {
  const data = localStorage.getItem('info')
  if (data) {
    LabName.value = JSON.parse(data).LabName
  }
  handleTime()
})
onUnmounted(() => {
  clearInterval(timeInfo.setInterval)
})
// todo 处理时间监听
const handleTime = () => {
  timeInfo.setInterval = setInterval(() => {
    const date = new Date()
    timeInfo.dateDay = formatTime(date, "HH: mm: ss")
    timeInfo.dateYear = formatTime(date, "yyyy年MM月dd日")
    timeInfo.dateWeek = WEEK[date.getDay()]
  }, 1000)
}
const emits = defineEmits(['changeCom'])
const changeCom = () => {
  emits('changeCom')
}
</script>

<style lang="scss" scoped>
.header-box {
  display: flex;
  height: 50px;

  .h-left {
    position: relative;
    flex: 1;
    background-image: url("../../assets/images/left.png");
    background-size: 100% 100%;

    .logo {
      height: 40px;
      margin: 10px 0 20px 40px;
    }
  }

  .h-center {
    display: flex;
    align-items: center;
    position: relative;
    height: 50px;
    margin-top: 2px;

    .c-bg {
      width: 105%;
      left: -2.5%;
      height: 100%;
      position: absolute;
      background-image: url("../../assets/images/text-bg.png");
      background-size: 100% 100%;
    }

    .c-text {
      position: relative;
      margin: 0 34px;
      font-size: 24px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #ffffff;
      line-height: 34px;
      letter-spacing: 3px;
      text-shadow: 0px 0px 24px #00ddff;
      padding-bottom: 10px;
    }
  }

  .h-right {
    flex: 1;
    background-image: url("../../assets/images/right.png");
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 40px;

    .system {
      &:hover {
        color: #5084e4;
      }

      transition: all 0.3s;
      cursor: pointer;

      img {
        width: 20px;
        margin-right: 5px;
      }

      display: flex;
      align-items: center;
      margin-left: 10px;
    }
  }
}
</style>
